<template>
  <div class="header_container">
    <a href="javascript:;" class="logo">
      <img src="@/assets/sand_logo.png" alt="Logo">
    </a>
    <nav id="navbar" class="navbar">
      <ul>
        <li
          v-for="item in category"
          :key="item.route"
          :class="{ dropdown: item.hasChildren }"
        >
          <router-link :to="item.route">
            {{ item.value }}
            <i :class="{ 'bi bi-chevron-down': item.hasChildren }"></i>
          </router-link>
          <ul v-if="item.hasChildren">
            <li v-for="child in item.children" :key="child.route">
              <router-link :to="child.route">{{ child.value }}</router-link>
            </li>
          </ul>
        </li>
      </ul>
      <i class="bi bi-list mobile-nav-toggle"></i>
    </nav>
  </div>
</template>

<script>
import category from '@/fake-data/category'

export default {
  name: 'HeaderSection',
  data () {
    return {
      category
    }
  }
}
</script>

<style lang="less" scoped>
.header_container {
  display: flex;
  align-items: center;
  max-width: 1320px;
  height: 50px;
  margin: 0 auto;

  .logo {
    font-size: 30px;
    margin: 0;
    padding: 0;
    line-height: 1;
    font-weight: 600;
    letter-spacing: 1px;
    text-transform: uppercase;
    margin-right: auto;

    img {
      max-height: 40px;
      max-width: 100%;
    }
  }

  .navbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    padding: 0;

    ul {
      margin: 0;
      padding: 0;
      display: flex;
      align-items: center;
    }

    a, a:focus {
      display: flex;
      align-items: center;
      justify-content: space-between;
      position: relative;
      padding: 10px 0 10px 30px;
      font-size: 15px;
      font-weight: 500;
      color: #37423b;
      white-space: nowrap;
      transition: 0.3s;

      i {
        font-size: 12px;
        line-height: 0;
        margin-left: 5px;
      }
    }

    a:hover {
      color: #0166ff;
    }

    .dropdown {
      ul {
        display: block;
        position: absolute;
        left: 30px;
        top: calc(100% + 30px);
        margin: 0;
        padding: 10px 0;
        z-index: 99;
        opacity: 0;
        visibility: hidden;
        background: #fff;
        box-shadow: 0px 0px 30px rgb(127 137 161 / 25%);
        transition: 0.3s;
        border-radius: 4px;

        li {
          min-width: 200px;
        }

        a {
          padding: 10px 20px;
          font-size: 14px;
          text-transform: none;
          font-weight: 500;
        }
      }
    }
    .dropdown:hover > ul {
      opacity: 1;
      top: 100%;
      visibility: visible;
    }
  }
}

.mobile-nav-toggle {
  color: #37423b;
  font-size: 28px;
  cursor: pointer;
  display: none;
  line-height: 0;
  transition: 0.5s;
}

.navbar > ul > li > a::before {
  content: '';
  position: absolute;
  left: 30px;
  height: 2px;
  bottom: 3px;
  background-color: #0166ff;
  visibility: hidden;
  width: 0px;
  transition: all 0.3s ease-in-out 0s;
}

.navbar a:hover::before, .navbar li:hover > a::before, .navbar .active::before {
  visibility: visible;
  width: 25px;
}

@media (max-width: 991px) {
  .mobile-nav-toggle {
    display: block;
  }

  .navbar ul {
    display: none;
  }
}

</style>
